package com.mask.bankthread;

public class Bank {
    private static volatile int count = 100;
    public static synchronized void save(String username, int money){
        count += money;
        System.out.println(username+ "存了" + money +"元钱");
        System.out.println("账户余额为:"+count+"元");
    }
}

class A implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            Bank.save("A",100);
        }
    }
}

class B implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            Bank.save("B",100);
        }
    }
}

class Test {
    public static void main(String[] args) {
        A a = new A();
        a.run();
        B b = new B();
        b.run();
    }
}

